package es.valma.VideoClub.service.base;

import es.valma.VideoClub.DAO.base.VideoClubSvClienteDao;
import es.valma.VideoClub.base.VideoClubSvCliente;
import es.valma.VideoClub.exception.DAO.base.VideoClubClienteDaoException;
import es.valma.VideoClub.exception.service.base.VideoClubSvClienteServiceException;

public class VideoClubSvClienteService {

	
	private VideoClubSvClienteDao clienteDao=null;
	private ControlBaseDatos control=null;
	
	public VideoClubSvClienteService(){
		clienteDao=new VideoClubSvClienteDao();
		control=new ControlBaseDatos();
	}
	
	
	public void insertarCliente(VideoClubSvCliente cliente){
		try{
			clienteDao.insertarCliente(cliente);
			control.Commit();
		}catch(VideoClubClienteDaoException e1){
			control.RollBack();
			throw(new VideoClubSvClienteServiceException("Error en el servicio cliente al insertar el cliente",e1));
		}
		
	}
	
	public VideoClubSvCliente buscarClientePorId(VideoClubSvCliente cliente){
		VideoClubSvCliente tmp=null;
		tmp = clienteDao.findById(cliente);
		return tmp;
	}
	
	public VideoClubSvCliente buscarClientePorDni(VideoClubSvCliente cliente){
		VideoClubSvCliente tmp=null;
		tmp=clienteDao.findByDNI(cliente);
		return tmp;
	}
	
	public VideoClubSvCliente buscarClientePorUsuario(VideoClubSvCliente cliente){
		VideoClubSvCliente tmp=null;
		tmp=clienteDao.findByUser(cliente);
		return tmp;
	}
	
	public boolean accesoClienteLogon(String user,String password){
		boolean logon=false;
		VideoClubSvCliente clienteLogandose=clienteDao.compruebaLogin(user, password);
		if(clienteLogandose!=null){
			logon=true;
		}
		return logon;
	}
	
}
